import Vue from 'vue'
import Vuex from 'vuex'
import CreatePersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

const vuexPersisted = new CreatePersistedState({
    storage: window.sessionStorage
})

const store = new Vuex.Store({
    strict: true,
    state: {
        username: '', // 实际上是员工id
        password: '',
        auth: '',
        emp_name: 'TestUser',
        department_id: '',
        department: '',
        usertype: -1,
        token: '',
        auth_str: ['普通员工', '部门经理', '副总经理', '总经理', '管理员'],
        dept_str: ['', '市场部', '财务部', '行政部']
    },
    mutations: {
        username(state, newName) {
            state.username = newName;
        },
        password(state, newPwd) {
            state.password = newPwd;
        },
        auth(state, newAuth) {
            state.auth = newAuth;
        },
        usertype(state, newType) {
            state.usertype = newType;
        },
        token(state, newToken) {
            state.token = newToken;
        },
        emp_name(state, newEmpName) {
            state.emp_name = newEmpName;
        },
        department(state, newDept) {
            state.department = newDept;
        },
        department_id(state, newDeptId) {
            state.department_id = newDeptId;
        }
    },
    actions: {

    },
    plugins: [vuexPersisted]
});

export default store;